package com.limm.controller;

import com.limm.cloud01.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class ConsumerController {


    @Autowired
    private RestTemplate restTemplate;

    //Ribbon 是通过服务名称去访问的
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-API";
//    private static final String REST_URL_PREFIX = "http://localhost:8001";

    @GetMapping("/consumer/selectByID/{id}")
    public Dept selectByID(@PathVariable Long dept_no) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/cloud/dept/selectByID/" + dept_no, Dept.class);

    }

    @GetMapping("/findAll")
    public List<Dept> findAll() {
        return restTemplate.getForObject(REST_URL_PREFIX+"/cloud/dept/findAll",List.class);
    }


}
